//
//  ProduceTableViewCell.m
//  ZYZB
//
//  Created by ENERGY on 2018/6/25.
//  Copyright © 2018年 ENERGY. All rights reserved.
//

#import "ProduceTableViewCell.h"
#import "ProduceCollectionViewCell.h"
@interface ProduceTableViewCell()<UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic, strong)UILabel * titleLab;//标题
@property (nonatomic, strong)NSString * firstTitleID;//一级标题ID
@property (nonatomic, strong)NSString * secondTitle;//二级标题
@property (nonatomic, strong)NSString * secondTitleID;//二级标题ID
@end
@implementation ProduceTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.contentView.backgroundColor = [UIColor whiteColor];
        __weak typeof(self) weakSelf = self;
        UIView * topLineView = [[UIView alloc] init];
        topLineView.backgroundColor = getColor(grayColor);
        //        topLineView.backgroundColor = [UIColor blackColor];
        [self.contentView addSubview:topLineView];
        [topLineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.right.equalTo(weakSelf);
            make.height.mas_offset(1/WIDTH_6_SCALE);
        }];
        UIView * bottomLineView = [[UIView alloc] init];
        bottomLineView.backgroundColor = getColor(grayColor);
        //        bottomLineView.backgroundColor = [UIColor blackColor];
        [self.contentView addSubview:bottomLineView];
        [bottomLineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.bottom.right.equalTo(weakSelf);
            make.height.mas_offset(1/WIDTH_6_SCALE);
        }];
        [self.contentView addSubview:self.titleLab];
        [self.contentView addSubview:self.collectionView];
        [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf.mas_top).mas_offset(15/WIDTH_6_SCALE);
            make.left.equalTo(weakSelf.mas_left).mas_offset(18/WIDTH_6_SCALE);
            make.height.mas_offset(12/WIDTH_6_SCALE);
        }];
        [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf.titleLab.mas_bottom).mas_offset(14/WIDTH_6_SCALE);
            make.bottom.equalTo(weakSelf.mas_bottom).mas_offset(-16/WIDTH_6_SCALE);
            make.left.right.equalTo(weakSelf);
        }];
    }return self;
}
#pragma mark - init
- (UILabel *)titleLab{
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] init];
        _titleLab.font = DEF_FontSize_14;
        _titleLab.textColor = [UIColor blackColor];
        _titleLab.textAlignment = NSTextAlignmentLeft;
        _titleLab.text = @"标的系列";
    }return _titleLab;
}
- (UICollectionView *)collectionView{
    if (!_collectionView) {
        UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc] init];
        layout.itemSize = CGSizeMake(218/WIDTH_6_SCALE, 80/WIDTH_6_SCALE);
        layout.minimumLineSpacing = 10/WIDTH_6_SCALE;
        layout.sectionInset = UIEdgeInsetsMake(0, 18/WIDTH_6_SCALE, 0, 18/WIDTH_6_SCALE);
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, 0, 0) collectionViewLayout:layout];
        _collectionView.showsVerticalScrollIndicator = NO;
        _collectionView.showsHorizontalScrollIndicator = NO;
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.backgroundColor = [UIColor whiteColor];
        [_collectionView registerClass:[ProduceCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([ProduceCollectionViewCell class])];
    }return _collectionView;
}
#pragma mark - collectionViewDelegate和collectionViewDataSource
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    ProduceCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([ProduceCollectionViewCell class]) forIndexPath:indexPath];
    cell.model = self.model[indexPath.row];
    return cell;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.model.count;
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    if ([[self.model[indexPath.row] objectForKey:@"twolab"] isEqualToString:@"供应链系列"]) {
        NSLog(@"%@", [self.model[indexPath.row] objectForKey:@"twolab"]);
        self.firstTitleID = @"1";
    }
    if ([[self.model[indexPath.row] objectForKey:@"twolab"] isEqualToString:@"惠民系列"]) {
        NSLog(@"%@", [self.model[indexPath.row] objectForKey:@"twolab"]);
        self.firstTitleID = @"1";
    }
    if ([[self.model[indexPath.row] objectForKey:@"twolab"] isEqualToString:@"福乐体验"]) {
        NSLog(@"%@", [self.model[indexPath.row] objectForKey:@"twolab"]);
        self.firstTitleID = @"1";
    }
    if ([[self.model[indexPath.row] objectForKey:@"twolab"] isEqualToString:@"公共服务系列"]) {
        NSLog(@"%@", [self.model[indexPath.row] objectForKey:@"twolab"]);
        self.firstTitleID = @"1";
    }
    if ([[self.model[indexPath.row] objectForKey:@"twolab"] isEqualToString:@"福乐月息"]) {
        NSLog(@"%@", [self.model[indexPath.row] objectForKey:@"twolab"]);
        self.firstTitleID = @"2";
    }
    if ([[self.model[indexPath.row] objectForKey:@"twolab"] isEqualToString:@"福乐白金"]) {
        NSLog(@"%@", [self.model[indexPath.row] objectForKey:@"twolab"]);
        self.firstTitleID = @"3";
    }
    self.secondTitleID = [self.model[indexPath.row] objectForKey:@"markid"];
    self.secondTitle = [self.model[indexPath.row] objectForKey:@"twolab"];
    if (self.produceSeriesBlock) {
        self.produceSeriesBlock(self.firstTitleID, self.secondTitleID, self.secondTitle);
    }
    
    
}
@end
